package com.idata.service.utils;

import cn.hutool.core.collection.CollectionUtil;
import com.idata.model.interfaces.HasDisputeTimeSortField;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class SortDisputeInfoUtil {
    public static List<Object> sortDisputeInfo(List<Object> disputeInfoList) {
        if (CollectionUtil.isEmpty(disputeInfoList)) {
            return new ArrayList<>();
        }
        List<HasDisputeTimeSortField> validDisputeInfoList = new ArrayList<>();
        for (Object disputeInfo : disputeInfoList) {
            if (disputeInfo == null) {
                continue;
            }
            if (!(disputeInfo instanceof HasDisputeTimeSortField)) {
                continue;
            }
            validDisputeInfoList.add((HasDisputeTimeSortField)disputeInfo);
        }
        Collections.sort(validDisputeInfoList);
        return validDisputeInfoList.stream().map(disputeInfo -> (Object) disputeInfo).collect(Collectors.toList());
    }
}
